; Music of Macadam Bumper (1985) (PSS & Ere)
; Ripped by Megachur the 29/04/2009

	write "MACADAMB.BIN"

music_date_rip	equ &1d49
music_adr	equ &7548
first_theme	equ 0
last_theme	equ 7	; 0 -> 7

	read "music_header_v1_0.asm"

	di
	ld bc,(#0039)
	ld (l755f),bc
	ld bc,l7574
	ld (#0039),bc
	ld a,#c9
	ld (#003b),a
	ei
	ret
.l755f
	db #00,#00
	di
	ld bc,(l755f)
	ld (#0039),bc
	exx
	ld bc,#7f8d
	exx
	or a
	ex af,af'
	ei
	ret
.l7573
	db #06
.l7574
	di
	push af
	push bc
	push de
	push hl
	push ix
	ld b,#f5
	in a,(c)
	rra
	jr nc,l758c
	ld a,(#7e56)
	or a
	call nz,#7de2
	call #684f
.l758c
	ld hl,l7573
	dec (hl)
	jr nz,l75e6
	ld (hl),#06
	ld hl,#b084
	dec (hl)
	jr nz,l759f
	ld a,#ff
	ld (#b006),a
.l759f
	ld hl,#b045
	ld a,(#0130)
	add (hl)
	daa
	ld (hl),a
	dec hl
	ld a,(hl)
	adc #00
	daa
	jr nc,l75b1
	ld a,#99
.l75b1
	ld (hl),a
	ld hl,#b043
	dec (hl)
	jr nz,l75cb
	ld hl,#b033
	ld a,(hl)
	or a
	jr nz,l75cb
	inc (hl)
	inc hl
	ld a,(hl)
	or a
	jr nz,l75cb
	ld a,(#b042)
	ld (#b00a),a
.l75cb
	call #68db
	call l75ee
	ld a,(l76a4)
	or a
	call nz,l76b5
	ld a,(l76aa)
	or a
	call nz,l76c8
	ld a,(l76b0)
	or a
	call nz,l76f0
.l75e6
	pop ix
	pop hl
	pop de
	pop bc
	pop af
	ei
	ret
.l75ee
	ld hl,#af36
	ld bc,#f40e
	out (c),c
	ld b,#f6
	in a,(c)
	and #30
	ld c,a
	or #c0
	out (c),a
	out (c),c
	inc b
	ld a,#92
	out (c),a
	ld bc,#f640
.l760b
	out (c),c
	ld a,#f4
	in a,(#00)
	ld (hl),a
	inc hl
	inc c
	ld a,c
	cp #4a
	jr c,l760b
	ld bc,#f700
	ld a,#82
	out (c),a
	dec b
	out (c),c
	ret
.l7624
	ld b,#f4
	di
	out (c),a
	ld b,#f6
	in a,(c)
	or #c0
	out (c),a
	and #3f
	out (c),a
	ld b,#f4
	out (c),c
	ld b,#f6
	ld c,a
	or #80
	out (c),a
	out (c),c
	ret
.l7643
	di
.l7644
	call l7662
	xor a
	ld (l76a4),a
	ld (l76b0),a
	ld c,a
	ld a,#08
	call l7624
	ld c,#38
	ld a,#07
	call l7624
	ld c,#00
	ld a,#0a
	jp l7624
.l7662
	xor a
	ld (l76aa),a
	ld c,#00
	ld a,#09
	jp l7624
.l766d
	ld hl,l76a6
	ld c,(hl)
	xor a
	call l7624
	inc hl
	ld c,(hl)
	ld a,#01
	call l7624
	ld a,(l76a4)
	ld c,a
	ld a,#08
	jp l7624
.l7685
	ld b,#00
	ld hl,l7807
	sla c
	add hl,bc
	ld c,(hl)
	inc hl
	ld h,(hl)
	ld a,#02
	call l7624
	ld c,h
	ld a,#03
	call l7624
	ld a,(l76aa)
	ld c,a
	ld a,#09
	jp l7624
.l76ab equ $ + 7
.l76aa equ $ + 6
.l76a8 equ $ + 4
.l76a7 equ $ + 3
.l76a6 equ $ + 2
.l76a5 equ $ + 1
.l76a4
	db #00,#00,#00,#00,#00,#00,#00,#00
.l76b3 equ $ + 7
.l76b2 equ $ + 6
.l76b1 equ $ + 5
.l76b0 equ $ + 4
.l76ae equ $ + 2
.l76ac
	db #00,#00,#00,#00,#00,#06,#00,#00
.l76b4
	db #00
.l76b5
	ld hl,l76b2
	dec (hl)
	ret nz
	ld a,(l76a5)
	ld (hl),a
	ld hl,l76a4
	dec (hl)
.l76c3 equ $ + 1
.l76c2
	call l76c2
	jp l766d
.l76c8
	ld hl,l76b3
	dec (hl)
	ret nz
	ld a,(l76ab)
	ld (hl),a
	ld hl,l76ac
	ld e,(hl)
	inc (hl)
	inc hl
	ld d,(hl)
	jr nz,l76db
	inc (hl)
.l76db
	ex de,hl
	ld a,(hl)
	sub #20
	ld c,a
	sla a
	jr nc,l7685
	jp nz,l7662
	ld bc,(l76ae)
	ld (l76ac),bc
	ret
.l76f0
	ld hl,l76b4
	dec (hl)
	ret nz
	ld a,(l76b1)
	ld (hl),a
	ld hl,l76b0
	dec (hl)
	ld c,#00
	ld a,#04
	call l7624
	ld c,#0d
	ld a,#05
	call l7624
	ld c,(hl)
	ld a,#0a
	jp l7624
.l7711
	ld hl,l76a6
	ld a,(hl)
	cp #46
	jr nc,l771b
	inc (hl)
	ret
.l771b
	dec (hl)
	ret
.l771d
	ld hl,(l76a6)
	ld bc,(l76a4)
	ld b,#00
	add hl,bc
	ld c,#10
	sbc hl,bc
	ld (l76a6),hl
	ret
.l772f
	ld hl,(l76a6)
	ld bc,(l76a4)
	ld b,#00
	sla c
	add hl,bc
	ld bc,#0020
	or a
	sbc hl,bc
	ld (l76a6),hl
	ret
.l7745
	ld hl,(l76a6)
	ld bc,#0020
	add hl,bc
	ld a,(l76a4)
	sla a
	ld c,a
	sbc hl,bc
	ld (l76a6),hl
	ret
.l7758
	call l772f
	ld a,(l76a4)
	cp #03
	ret nc
	xor a
	ld hl,l76a8
	dec (hl)
	jr z,l776c
	dec hl
	inc (hl)
	ld a,#0f
.l776c
	ld (l76a4),a
	ret
.l7770
	ld a,(l76a8)
	bit 2,a
	ld bc,#ffe7
	jr nz,l777d
	ld bc,#0019
.l777d
	ld a,(hl)
	cp #0c
	jr nc,l7783
	inc (hl)
.l7783
	ld hl,(l76a6)
	add hl,bc
	ld (l76a6),hl
	ld hl,l76a8
	xor a
	dec (hl)
	jr z,l776c
	ret
;
.l7792
;
	ld b,#00
	push bc
	push hl
	ld hl,l788b
	add hl,bc
	ld c,(hl)
	inc hl
	ld b,(hl)
	di
	ld (l76c3),bc
	inc hl
	ld a,(hl)
	ld (l76a5),a
	inc hl
	ld a,(hl)
	ld (l76a8),a
	inc hl
	ld c,(hl)
	inc hl
	ld b,(hl)
	ld (l76a6),bc
	ld a,#01
	ld (l76b2),a
	ld a,#10
	ld (l76a4),a
	pop hl
	pop bc
	ld a,c
	cp #18
	jr nz,l77ca
	ld a,#0d
	ld (l76a4),a
.l77ca
	cp #36
	jr nz,l77e0
	ld a,(#afed)
	rlca
	rlca
	rlca
	add #64
	ld (l76a6),a
	jr nc,l77e0
	ld a,#01
	ld (l76a7),a
.l77e0
	ei
	ret
.l77e2
	push hl
	ld hl,l78c7
	ld b,#00
	add hl,bc
	ld c,(hl)
	inc hl
	ld b,(hl)
	di
	ld (l76ac),bc
	ld (l76ae),bc
	inc hl
	ld a,(hl)
	ld (l76ab),a
	ld a,#01
	ld (l76b3),a
	ld a,#0b
	ld (l76aa),a
	ei
	pop hl
	ret
.l7807
	dw #02a4,#027e,#025a,#0238
	dw #0218,#01fa,#01de,#01c3
	dw #01aa,#0192,#017b,#0166
	dw #0152,#013f,#012d,#011c
	dw #010c,#00fd,#00ef,#00e1
	dw #00d5,#00c9,#00be,#00b3
	dw #00a9,#009f,#0096,#008e
	dw #0086,#007f,#0077,#0071
	dw #006a,#0064,#005f,#0059
	dw #0054,#0050,#004b,#0047
	dw #0043,#003f,#003c,#0038
	dw #0035,#0032,#002f,#002d
	dw #002a,#0028,#0026,#0024
	dw #0022,#0020,#001e,#001c
	dw #001b,#0019,#0018,#0016
	dw #0015,#0014,#0013,#0012
	dw #0011,#0010
.l788b
	dw l771d,#0005,#0400,l771d
	dw #0002,#0060,l771d,#0001
	dw #01a0,l772f,#0002,#0070
	dw l7711,#0002,#001c,l7758
	dw #1901,#0100,l772f,#0001
	dw #00c0,l7745,#0002,#0046
	dw l7770,#1402,#00b0,l771d
.l78c7 equ $ + 4
	dw #0001,#0000,l78e7,#0007
	dw l7967,#0007,l7975,#0007
	dw l797d,#0008,l7993,#0008
	dw l79a1,#0008,l79b1,#0008
	dw l79c1,#0008
.l78e7
	db #44,#43,#41,#41,#3f,#3f,#3c,#38
	db #3a,#3c,#3a,#3c,#3a,#38,#35,#37
	db #33,#35,#38,#3a,#38,#37,#38,#3a
	db #3c,#3d,#41,#41,#43,#41,#3f,#3f
	db #44,#43,#41,#43,#41,#3f,#3c,#38
	db #3a,#3c,#3a,#3c,#3a,#38,#35,#35
	db #37,#35,#33,#35,#37,#3a,#3f,#3a
	db #37,#33,#38,#37,#38,#3a,#38,#35
	db #33,#37,#38,#37,#38,#3a,#3c,#3f
	db #41,#43,#44,#43,#44,#46,#44,#41
	db #3f,#3d,#3c,#3a,#38,#3a,#3c,#3f
	db #41,#43,#44,#44,#43,#44,#43,#43
	db #44,#43,#41,#41,#3f,#3f,#3c,#3c
	db #38,#3c,#3a,#3c,#3a,#38,#35,#35
	db #37,#35,#33,#35,#37,#3a,#3f,#3a
	db #37,#33,#38,#37,#38,#3a,#38,#a0
.l7967
	db #20,#22,#24,#25,#27,#29,#27,#25
.l7975 equ $ + 6
	db #24,#20,#22,#24,#20,#c8,#44,#43
.l797d equ $ + 6
	db #44,#3f,#3c,#3f,#44,#c8,#3f,#41
	db #43,#44,#46,#43,#46,#43,#44,#48
	db #46,#44,#43,#3f,#3a,#3e,#3f,#41
.l7993 equ $ + 4
	db #43,#44,#46,#c8,#3f,#3c,#3a,#3f
	db #3c,#3a,#37,#3a,#3c,#3a,#37,#35
.l79a1 equ $ + 2
	db #33,#c8,#44,#46,#48,#44,#43,#44
	db #46,#43,#41,#43,#44,#41,#3f,#3d
.l79b1 equ $ + 2
	db #3c,#c8,#3c,#3a,#38,#37,#38,#3a
	db #38,#33,#30,#31,#33,#35,#33,#30
.l79c1 equ $ + 2
	db #33,#c8,#46,#45,#46,#41,#46,#45
	db #46,#41,#46,#45,#46,#41,#43,#41
	db #3e,#3c,#3a,#c8
	
;
.init_music	; added by Megachur
;
	rla
	rla
	push af
	ld a,&3a
	ld (l90cc),a
	call l7644
	pop af
	or a
	jr z,init_music_or_sound_fx
	ld c,a
	ld a,&c9
	ld (l90cc),a
	jp l77e2
;
.init_music_or_sound_fx
;
	ld hl,l90ec
.l90c1
	ld a,(hl)
	or a
	jp z,l90df
	inc hl
	ld c,(hl)
	inc hl
	call l90d8
;jr l90c1
	ld (init_music_or_sound_fx+1),hl
	ret
.l90d8
	dec a
	jp z,l7792
	jp l77e2
.l90df
	ld hl,l90ec
	ld (init_music_or_sound_fx+1),hl
	ret
.l90ec
	db #01,#30,#02,#0c,#01,#12,#01,#24
	db #02,#1c,#01,#30,#00
	
;
.play_music	; added by Megachur
;
	ld a,(l76a4)
	or a
	call nz,l76b5
	ld a,(l76aa)
	or a
	call nz,l76c8
	ld a,(l76b0)
	or a
	call nz,l76f0
	
.l90cc
	ld a,(l76a4)
	ld b,a
	ld a,(l76aa)
	or b
	ret nz
	jp init_music_or_sound_fx

; #7a9c
;ld a,(#b03b)
;or a
;ret z
;call #7643
;ei
;ld c,#1e
;call #7792
;xor a
;ld (#b03b),a
;
.game_name
	db "Macadam Bumper",0
.game_year
	db "1985",0
.game_publisher
	db "PSS & Ere",0
.music_author
	db "",0
.music_comment
	db "",0

	read "music_end_v1_0.asm"
